<template>
  <div class="app-container">
    <el-table v-loading="loading" border :data="tableList">
      <el-table-column label="访问内容" align="center" prop="accessContent" />
      <el-table-column label="访问开始时间" align="center" prop="beginTime" />
      <el-table-column label="访问结束时间" align="center" prop="endTime" />
      <el-table-column label="观看时长" align="center" prop="accessInterval">
        <template slot-scope="scope">
          {{ (scope.row.accessInterval / 60).toFixed(2) }}分钟
        </template>
      </el-table-column>
      <el-table-column label="信息来源" align="center" prop="source">
        <template slot-scope="scope">
          {{
            getValue(sourceOptions, scope.row.source)
              ? getValue(sourceOptions, scope.row.source)
              : scope.row.source
          }}
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getDetailList } from "@/api/visitorManagement/index";
export default {
  props: {
    accessCode: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      tableList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 视频来源
      sourceOptions: [{ value: "0", label: "视频详情" }],
    };
  },
  watch: {
    accessCode: {
      handler() {
        this.getList();
      },
      immediate: true,
    },
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      getDetailList({
        ...this.queryParams,
        accessCode: this.accessCode,
      }).then((response) => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表格根据value获取label
    getValue(options, value) {
      return options.find((item) => item.value === value)?.label;
    },
  },
};
</script>
